home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
raytrace
/
rayshade
/
graphtal.lzh
/
Graphtal.Amiga
/
Name.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-20
|
2KB
|
78 lines
/*
* Name.C - methods for space efficient name storage.
*
* Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
* University of Berne, Switzerland
* Portions Copyright (C) 1990, Jonathan P. Leech
* All rights reserved.
*
* This software may be freely copied, modified, and redistributed
* provided that this copyright notice is preserved on all copies.
*
* You may not distribute this software, in whole or in part, as part of
* any commercial product without the express consent of the authors.
*
* There is no warranty or other guarantee of fitness of this software
* for any purpose. It is provided solely "as is".
*
*/
#include "Name.h"
implementList(rcStringList, rcStringPtr);
implementList(NameList, NamePtr);
//___________________________________________________________ Name
rcStringList* Name::GlobalNameSpace = new rcStringList(100);
// the string name will be copied
Name::Name(const char* name)
{
index_ = addname(name);
}
// the string name will be copied
Name::Name(const rcString* name)
{
index_ = addname(name->chars());
}
const Name& Name::operator=(const Name& aName)
{
index_ = aName.index_;
return *this;
}
Name::operator const char*() const
{
return GlobalNameSpace->item(index_)->chars();
}
long Name::addname(const char* name)
{
int found = 0;
register long i;
// is the name already in the list?
for (i=0; i<GlobalNameSpace->count(); i++)
if (*GlobalNameSpace->item(i) == name) {
found = 1;
break;
}
// not in the list yet -> append it
if (!found)
GlobalNameSpace->append(new rcString(name));
return i;
}
ostream& operator<<(ostream& os, const Name& aName)
{
return os << (const char*) aName;
}